package com.ht.shop.dao.impl;

import com.ht.shop.dao.OrderListDao;

import com.ht.shop.pojo.TbOrder;
import com.ht.shop.utils.DBUtils;
import com.ht.shop.utils.SqlUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;


import java.sql.SQLException;
import java.util.List;


public class OrderListDaoImpl implements OrderListDao {
    private QueryRunner queryRunner = new QueryRunner(DBUtils.getSource());



    @Override
    public List<TbOrder> findAllListById(Long uid) throws Exception {
        String sql = SqlUtils.getSql("orderlist.detail");
        List<TbOrder> query = queryRunner.query(sql, new BeanListHandler<>(TbOrder.class), uid);
        return query;
    }

    @Override
    public void deleteById(String id) {
        String sql = SqlUtils.getSql("orderlist.delete");
        try {
            queryRunner.update(sql,id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }


    @Override
    public List<TbOrder> findAllListById() throws Exception {
        String sql = SqlUtils.getSql("orderlist.findAll");
        List<TbOrder> query = queryRunner.query(sql, new BeanListHandler<>(TbOrder.class));
        return query;
    }
}
